﻿var lang;
var year = ['2009', '2008', '2007', '2006', '2005', '2004', '2003', '2002', '2001', '2000', '1999'];

$(document).ready(function () {
    lang = getPageLang();
    if ($("#StampPoll2009_Stamp").length > 0) {
        $("#StampPoll2009_Stamp").tabs();
        $.get("/xml/activities/2009stamppoll/stamp.xml", {}, parseXML);
    }
    if ($("#StampPoll2009_Souvenir").length > 0) {
        $("#StampPoll2009_Souvenir").tabs();
        $.get("/xml/activities/2009stamppoll/souvenir.xml", {}, parseXML);
    }
});

function parseXML(xml) {
    for (i = 0; i < year.length; i++) {
        var output = '<ul class="stamplists">';
        $(xml).find('stamp[year=' + year[i] + ']').each(function () {
            stampImageCode = $(this).find("image").text();
            stampImagePath = $(this).find("image").attr("path");
            stampName = $(this).find("name[lang=" + lang + "]").text();
            output += '<li><a class="fancybox" rel="y' + year[i] + '" title="' + stampName + '" href="' + stampImagePath + '/large/' + stampImageCode + '.jpg" target="_blank"><img src="' + stampImagePath + '/thumb/' + stampImageCode + '.jpg" alt="' + stampName + '"></a></li>';
        });
        output += "</ul>";
        $("#Y" + year[i]).append(output);
    }
    $("a.fancybox").fancybox();
}

function getPageLang() {
    var language = $("meta[http-equiv=Content-Language]").attr("content");
    if (!language) {
        language = $("meta[httpEquiv=Content-Language]").attr("content"); // For IE6
    }
    switch (language) {
        case "zh-tw":
            return "chi";
            break;
        case "zh-cn":
            return "chis";
            break;
        case "pt":
            return "por";
            break;
        case "en-gb":
            return "eng";
            break;
        default:
            return "eng";
            break;
    }
}